<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:loc="clr-namespace:Jerry.DroidBuilder"
  xmlns:ext="clr-namespace:Jerry.DroidBuilder.Extensions"
  xmlns:ctrl="clr-namespace:Jerry.DroidBuilder.Controls"
  xmlns:local="clr-namespace:Jerry.DroidBuilder">
  <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>

  <HierarchicalDataTemplate x:Key="TreeListViewItemTemplate" ItemsSource="{Binding SubItems}"/>

  <DataTemplate x:Key="NameTemplate">
    <StackPanel Orientation="Horizontal" Margin="-4,0,0,0">
      <Grid>
        <Border Width="6" Height="6" Background="#595959" Margin="4,2"/>
        <Image Width="16" Height="16" Source="../Images/folder.png" Visibility="{Binding IsDirectory, Converter={StaticResource BooleanToVisibilityConverter}}"/>
      </Grid>
      <CheckBox IsChecked="True" Visibility="{Binding IsApk, Converter={StaticResource BooleanToVisibilityConverter}}"/>
      <TextBlock Text="{Binding Name}" VerticalAlignment="Center" Margin="0,-1,0,1"/>
    </StackPanel>
  </DataTemplate>

  <ContextMenu x:Key="ContextMenuForItem">
    <MenuItem
        Header="{loc:Localize Menu_Expand}"
        Command="{Binding DataContext.ExpandItemCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ctrl:TreeListView}}}"
        CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ctrl:TreeListView}}}"/>
    <Separator/>
    <MenuItem Header="Open"/>
    <MenuItem Header="Delete"/>
    <Separator/>
    <MenuItem Header="Translate"/>
    <MenuItem Header="Merge to *.apk"/>
  </ContextMenu>

  <Style TargetType="{x:Type ctrl:TreeListViewItem}" BasedOn="{StaticResource {x:Type ctrl:TreeListViewItem}}">
    <Setter Property="ContextMenu" Value="{StaticResource ContextMenuForItem}"/>
    <Setter Property="ext:CommandExtension.Command" Value="{Binding DataContext.OpenItemCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ctrl:TreeListView}}}"/>
    <Setter Property="ext:CommandExtension.RoutedEvent" Value="Control.MouseDoubleClick"/>
    <Setter Property="ext:CommandExtension.CommandParameter" Value="{Binding}"/>
  </Style>

  <DataTemplate DataType="{x:Type local:RomDirectoryViewModel}">
    <Grid>
      <ctrl:TreeListView
        ItemsSource="{Binding SourceItems}"
        ItemTemplate="{StaticResource TreeListViewItemTemplate}"
        ext:CommandExtension.Command="{Binding ContextMenuOpeningCommand}"
        ext:CommandExtension.RoutedEvent="FrameworkElement.ContextMenuOpening"
        ext:CommandExtension.UseArgumentAsParameter="True"
        ext:ColumnExtension.IsEnabled="True">
        <ctrl:TreeListView.Columns>
          <GridViewColumn Header="Name" CellTemplate="{StaticResource NameTemplate}" ext:ColumnExtension.Width="*" ext:ColumnExtension.MinWidth="120"/>
          <GridViewColumn Header="Size" Width="80" ext:ColumnExtension.MinWidth="80" DisplayMemberBinding="{Binding SystemInfo.Length}"/>
          <GridViewColumn Header="Last Modified" Width="120" ext:ColumnExtension.MinWidth="120" DisplayMemberBinding="{Binding SystemInfo.LastWriteTime}"/>
        </ctrl:TreeListView.Columns>
      </ctrl:TreeListView>
    </Grid>
  </DataTemplate>
</ResourceDictionary>